package alvarodelrosal.chat.server.modelo.chataction;

import alvarodelrosal.chat.server.infraestructura.ChatLiveConversations;
import alvarodelrosal.chat.server.modelo.ChatConnection;
import alvarodelrosal.chat.server.modelo.ChatConversation;
import java.util.List;

public class ChatNewChat implements ChatAction {

    @Override
    public String getName() {
        return "NewChat";
    }

    @Override
    public boolean needsAdminPrivileges() {
        return false;
    }

    @Override
    public boolean needsLogin() {
        return true;
    }

    @Override
    public String doAction(ChatConnection connection, List<String> parameters) {
        int nextConversationId = ChatLiveConversations.getNextConversationId();
        ChatConversation conversation = new ChatConversation(nextConversationId, parameters.get(0));
        conversation.addConnection(connection);
        ChatLiveConversations.addConversation(conversation);
        return "NewChat<:@:>" + String.valueOf(nextConversationId);
    }
    
}
